home *** CD-ROM | disk | FTP | other *** search
/ Interactive Web Graphics with Shout 3D / Interactive Web Graphics With Shout 3D.iso / mac / Shout3Ddemo / S3D_2E1.exe / Shout3d_runtime / codebase / applets / HAnimExaminePanel.java < prev    next >
Text File  |  2000-09-01  |  4KB  |  131 lines

  1. //  Copyright 2000  Eyematic Interfaces, Inc.
  2. //  All rights reserved.
  3.  
  4.  
  5. package applets;
  6.  
  7.  
  8. import shout3d.core.Node;
  9. import shout3d.core.Renderer;
  10. import shout3d.core.Searcher;
  11. import shout3d.core.StringArrayField;
  12.  
  13. import shout3d.hanim.Humanoid;
  14. import shout3d.hanim.Joint;
  15. import shout3d.hanim.Segment;
  16.  
  17.  
  18. /**
  19.  *  Demonstrates how to obtain references to the humanoids in a scene.
  20.  */
  21. public class HAnimExaminePanel extends ExaminePanel
  22. {
  23.     private boolean done;
  24.     
  25.     
  26.     public HAnimExaminePanel(HAnimExamineApplet applet)
  27.     {
  28.         super(applet);
  29.         
  30.         done = false;
  31.     }
  32.     
  33.  
  34.     /**
  35.      *  Overrides the RenderObserver method implementation in the
  36.      *  ExaminePanel superclass.
  37.      */
  38.     public void onPostRender(Renderer renderer, Object data)
  39.     {
  40.         super.onPostRender(renderer, data);
  41.         
  42.         if (!done)
  43.         {
  44.             Node        root        = getScene();
  45.             Searcher    searcher    = getNewSearcher();
  46.             
  47.             searcher.setType("Humanoid");
  48.             
  49.             Node[][] paths = searcher.searchAll(root);
  50.             
  51.             if (null == paths)
  52.                 System.out.println("no Humanoid nodes found");
  53.             else
  54.                 for (int p = 0; p < paths.length; ++p)
  55.                 {
  56.                     Node[] path = paths[p];
  57.                     
  58.                     Humanoid humanoid = (Humanoid)path[path.length - 1];
  59.                     
  60.                     dumpHumanoid(humanoid);
  61.                 }
  62.             
  63.             done = true;
  64.         }
  65.     }
  66.     
  67.     
  68.     private void dumpHumanoid(Humanoid humanoid)
  69.     {
  70.         System.out.println();
  71.         
  72.         System.out.println(humanoid.name.getValue() + ": Humanoid");
  73.         for (int i = 0; i < humanoid.info.getValue().length; ++i)
  74.             System.out.println("\t\t" + humanoid.info.getValue()[i]);
  75.         
  76.         dumpJoint(getHumanoidRoot(humanoid), 1);
  77.         
  78.         System.out.println();
  79.     }
  80.     
  81.     
  82.     private void dumpJoint(Joint joint, int level)
  83.     {
  84.         for (int i = 0; i < level; ++i)
  85.             System.out.print("\t");
  86.             
  87.         System.out.println(joint.name.getValue() + ": Joint");
  88.         
  89.         for (int i = 0; i < joint.children.getLength(); ++i)
  90.         {
  91.             Node child = joint.children.getValue()[i];
  92.             if (child instanceof Joint)
  93.                 dumpJoint((Joint)child, level + 1);
  94.             else if (child instanceof Segment)
  95.                 dumpSegment((Segment)child, level + 1);
  96.         }
  97.     }
  98.     
  99.     
  100.     private void dumpSegment(Segment segment, int level)
  101.     {
  102.         for (int i = 0; i < level; ++i)
  103.             System.out.print("\t");
  104.             
  105.         System.out.println(segment.name.getValue() + ": Segment");
  106.     }
  107.     
  108.     
  109.     /**
  110.      *  Returns the first Joint in humanoidBody named HumanoidRoot.
  111.      *  Note that humanoids with more than one root are malformed.
  112.      */
  113.     private Joint getHumanoidRoot(Humanoid humanoid)
  114.     {
  115.         Joint root = null;
  116.         
  117.         for (int i = 0; i < humanoid.humanoidBody.getLength(); ++i)
  118.             if (humanoid.humanoidBody.getValue()[i] instanceof Joint)
  119.             {
  120.                 Joint joint = (Joint)humanoid.humanoidBody.getValue()[i];
  121.                 if (joint.name.getValue().equals("HumanoidRoot"))
  122.                 {
  123.                     root = joint;
  124.                     break;
  125.                 }
  126.             }
  127.             
  128.         return root;
  129.     }
  130. }
  131.